import getApiData, { getCPASTableAipsData, getNestApiData, postCPASTableAipsData } from "@/services/cpasRequest";
import {
  queryVerifyState,
} from "@/services/annotaionAnalysis";
export const queryVerifyStatefs = async (params: any) => {
  const res = await queryVerifyState(params)
  return res
}


// 获取账套
export async function getAccountInfo(params: {
  dbname: string;
}) {
  try {
    const res = await getApiData("account.cpastable.ssphDataList", params);
    if (res.ok) {
      return Promise.resolve({
        data: res.data,
        success: true,
      });
    }
    return Promise.resolve({
      data: res.data,
      success: false,
    });
  } catch (error) {
    return Promise.resolve({
      data: '接口ssphDataList出错了！',
      success: false,
    });
  }
}



export async function getYearADate(params: {
  dbname: string;
  Data_ID: string;
}) {
  try {
    const res = await getApiData("cpasTable.getYearADate", params);
    if (res.ok) {
      return Promise.resolve({
        data: res.data,
        success: true,
      });
    }
    return Promise.resolve({
      data: res.data,
      success: false,
    });
  } catch (error) {
    return Promise.resolve({
      data: '接口getYearADate出错了！',
      success: false,
    });
  }
}

// 校验结果
export async function gettableIsVerifyTid(params: {
  tableName: string;
  dbname: string;
  isTid: boolean
}) {
  try {
    const res = await getApiData("account.design_table.isVerifyAndTid", params);
    if (res.ok) {
      return Promise.resolve({
        data: res.data,
        success: true,
      });
    }
    return Promise.resolve({
      data: '接口account.design_table.isVerify出错了！',
      success: false,
    });
  } catch (error) {
    return Promise.resolve({
      data: '接口account.design_table.isVerify出错了！',
      success: false,
    });
  }
}




/**
 * 获取基础报表数据列映射
 */
export const getColumnsMapByReport = async (params: any) => {
  try {
    const res = await getCPASTableAipsData('getColumnsMapByReport', params)
    if (res.ok) {
      return Promise.resolve({
        data: res.data,
        success: true,
      });
    }
    return Promise.resolve({
      data: res.data,
      success: false,
    });
  } catch (error) {
    return Promise.resolve({
      data: '接口getRowsMapByReport出错了！',
      success: false,
    });
  }

};

/**
 * 获取报表基础数据行映射
 * @param tid
 */
export const getRowsMapByReport = async (params: any) => {

  try {
    const res = await getCPASTableAipsData('getRowsMapByReport', params)
    if (res.ok) {
      return Promise.resolve({
        data: res.data,
        success: true,
      });
    }
    return Promise.resolve({
      data: res.data,
      success: false,
    });
  } catch (error) {
    return Promise.resolve({
      data: '接口getRowsMapByReport出错了！',
      success: false,
    });
  }

};

/**
 * 获取表数据根据name
 */

export const getDesignTableInfoByNameApi = async (params: any) => {
  try {
    const res = await getCPASTableAipsData('getCpasTableDataByName', params)
    if (res.ok) {
      return Promise.resolve({
        data: res.data,
        success: true,
      });
    }
    return Promise.resolve({
      data: res.data,
      success: false,
    });
  } catch (error) {
    return Promise.resolve({
      data: '接口getCpasTableDataByName出错了！',
      success: false,
    });
  }

};



export async function getSsphData(params: {
  dbname: string;
  data_ID: string;
  cols: string;
  keys: string
}) {
  try {
    const res = await getApiData("account.ssph", params);
    if (res.ok) {
      return Promise.resolve({
        data: res.data,
        success: true,
      });
    }
    return Promise.resolve({
      data: res.data,
      success: false,
    });
  } catch (error) {
    return Promise.resolve({
      data: '接口account.ssph出错了！',
      success: false,
    });
  }

}

// 初始化模板
export async function templateInitApi(params: {
  dbName: string;
  templateName: string;
  tableNames?: string[];
  type: string;
  dataId?: string;
}) {
  try {
    const res = await getNestApiData('/template/importTemplate', 'post', params)
    if (res.ok) {
      return Promise.resolve({
        data: res.ok,
        msg: res.msg,
        success: true,
      });
    }
    return Promise.resolve({
      data: res.ok,
      msg: res.msg,
      success: false,
    });
  } catch (error) {
    return Promise.resolve({
      data: '接口/template/importTemplate,请求失败！',
      success: false,
    });
  }
}


// 保存模板
export async function saveTemplateApi(params: {
  dbName: string;
  templateName: string;
  tableNames?: string[];
  type: string;
  dataId?: string;
}) {
  try {
    const res = await getNestApiData("/template/exportDataToSqlite", "post", params);
    if (res.ok) {
      return Promise.resolve({
        data: res.data,
        msg: res.msg,
        success: true,
      });
    }
    return Promise.resolve({
      data: res.data,
      msg: res.msg,
      success: false,
    });
  } catch (error) {
    return Promise.resolve({
      data: "接口/template/exportDataToSqlite,请求失败！",
      success: false,
    });
  }
}

/**
 * 批量清空数据
 */
export const batchClearData = async (params: any) => {
  try {
    const res = await getNestApiData('/cpasTableOperation/batchClearCpasTableData', "post", params)
    if (res.ok) {
      return Promise.resolve({
        data: res.data,
        msg: res.msg,
        success: true,
      });
    }
    return Promise.resolve({
      data: res.data,
      msg: res.msg,
      success: false,
    });
  } catch (error) {
    return Promise.resolve({
      data: '接口batchClearCpasTableData出错了！',
      success: false,
    });
  }
};

/**
 * 批量清空数据
 */
export const batchClearGSData = async (params: any) => {
  try {
    const res = await getNestApiData('/cpasTableOperation/batchClearFormulas', "post", params)
    if (res.ok) {
      return Promise.resolve({
        data: res.data,
        msg: res.msg,
        success: true,
      });
    }
    return Promise.resolve({
      data: res.data,
      msg: res.msg,
      success: false,
    });
  } catch (error) {
    return Promise.resolve({
      data: '接口batchClearFormulas出错了！',
      success: false,
    });
  }
};


/**
 * 
 */
export const batchVerifyRecal = async (params: any) => {
  try {
    const res = await getNestApiData('/cpasTableOperation/batchVerifyRecalculate', "post", params)
    if (res.ok) {
      return Promise.resolve({
        data: res.data,
        msg: res.msg,
        success: true,
      });
    }
    return Promise.resolve({
      data: res.data,
      msg: res.msg,
      success: false,
    });
  } catch (error) {
    return Promise.resolve({
      data: '接口batchVerifyRecalculate出错了！',
      success: false,
    });
  }
};


export async function getCpasAllTids(params: {
  dbname: string;
  originTableName: string;
  isAllTid: boolean;
}) {
  try {
    const res = await getApiData("account.design_table.allTids", params);
    if (res.ok) {
      return Promise.resolve({
        data: res.data,
        success: true,
      });
    }
    return Promise.resolve({
      data: res.data,
      success: false,
    });
  } catch (error) {
    return Promise.resolve({
      data: '接口getCpasAllTids出错了！',
      success: false,
    });
  }
}




// reloadBatchDataRecalculateFs
export async function reloadBatchDataRecalculateFs(params: {
  dbname: string;
  allParameters: any;
  negationRow: string[];
  data_id?: string;
}) {
  try {
    const res = await getNestApiData("/cpasTableOperation/batchDataRecalculateFs", "post", params);
    if (res.ok) {
      return Promise.resolve({
        data: res.data,
        msg: res.msg,
        success: true,
      });
    }
    return Promise.resolve({
      data: res.data,
      msg: res.msg,
      success: false,
    });
  } catch (error) {
    return Promise.resolve({
      data: "接口/template/exportDataToSqlite,请求失败！",
      success: false,
    });
  }
}
// CpasTable批量重算
export enum BatchOperationType {
  DATA_RECALCULATE = "dr",  //  数据批量重算
  VERIFY_RECALCULATE = "vr", // 勾稽重算
  VERIFY_STATISTICS = "vs",  //勾稽重算,带有统计信息
  DATA_VERIFY_RECALCULATE = "dvr" // 批量重算,勾稽重算组合.不需要勾稽信息
}
export async function reCalculateCpasTable(params: any) {
  try {
    const res = await getNestApiData("/cpasTableOperation/batchDataAndVerifyRecalculate", "post",
      {
        ...params,
        type: BatchOperationType.DATA_VERIFY_RECALCULATE
      });
    return Promise.resolve({
      data: res.data,
      msg: res.msg,
      success: res.ok,
    });
  } catch (error) {
    return Promise.resolve({ data: error, ok: false, code: 100000 });
  }
}
/**
 * 获取校验数据列映射
 */
export const getVerifyByRMap = async (params: any) => {
  try {
    const res = await getCPASTableAipsData('getVerifyByRMap', params);
    if (res.ok) {
      return Promise.resolve({
        data: res.data,
        success: true,
      });
    }
    return Promise.resolve({
      data: res.data,
      success: false,
    });
  } catch (error) {
    return Promise.resolve({
      data: '接口getVerifyByRMap出错了！',
      success: false,
    });
  }
};
/**
 * 获取
 */
export const getVerifyDataList = async (params: any) => {
  try {
    const res = await postCPASTableAipsData('getVerifyDataList', params);
    if (res.ok) {
      return Promise.resolve({
        data: res.data,
        success: true,
      });
    }
    return Promise.resolve({
      data: res.data,
      success: false,
    });
  } catch (error) {
    return Promise.resolve({
      data: '接口getVerifyDataList出错了！',
      success: false,
    });
  }
};
// export async function getjudgmentInit(params: {
//   dbname: string;
//   type: string;
//   tableName?: string;
//   tableRealName: string;
// }) {
//   try {
//     const res = await getApiData("account.judgmentInit", params);
//     if (res.ok) {
//       return Promise.resolve({
//         data: res.data,
//         success: true,
//       });
//     }
//     return Promise.resolve({
//       data: '接口account.judgmentInit出错了！',
//       success: false,
//     });
//   } catch (error) {
//     return Promise.resolve({
//       data: '接口account.judgmentInit出错了！',
//       success: false,
//     });
//   }
// };

// export async function getSeekAuditReportTemplate(params: {
//   zcbfid: string;
// }) {
//   try {
//     const res = await getApiData("account.seekAuditReportTemplate", params);
//     if (res.ok) {
//       return Promise.resolve({
//         data: res.data,
//         success: true,
//       });
//     }
//     return Promise.resolve({
//       data: '接口account.seekAuditReportTemplate出错了！',
//       success: false,
//     });
//   } catch (error) {
//     return Promise.resolve({
//       data: '接口account.seekAuditReportTemplate出错了！',
//       success: false,
//     });
//   }
// };
